#!/bin/bash

ROOTFS=$1

mount -t proc /proc $ROOTFS/proc || exit 1
mount -t sysfs /sys $ROOTFS/sys || exit 1
mount -o bind /dev $ROOTFS/dev || exit 1
mount -o bind /dev/pts $ROOTFS/dev/pts || exit 1
mount -t tmpfs tmpfs $ROOTFS/run || exit 1

# trap
cleanup() {
    umount -l $ROOTFS/run
    umount -l $ROOTFS/dev/pts
    umount -l $ROOTFS/dev
    umount -l $ROOTFS/proc
    umount -l $ROOTFS/sys
}
trap cleanup EXIT

chroot $ROOTFS /bin/bash
